package main

import "fmt"

func solution(n int, maxVal int, array []int) []int {
	freq := make(map[int]int)
	for _, card := range array {
		freq[card]++
	}

	order := []int{1, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2}
	var aCandidates []int
	var bCandidates []int

	for _, card := range order {
		if freq[card] >= 3 {
			aCandidates = append(aCandidates, card)
		}
		if freq[card] >= 2 {
			bCandidates = append(bCandidates, card)
		}
	}

	for _, a := range aCandidates {
		for _, b := range bCandidates {
			if b != a && (3*a+2*b) <= maxVal {
				return []int{a, b}
			}
		}
	}

	return []int{0, 0}
}


func main() {
	fmt.Println(solution(9, 34, []int{6, 6, 6, 8, 8, 8, 5, 5, 1}))  // 应输出[8 5]

	fmt.Println(solution(9, 37, []int{9, 9, 9, 9, 6, 6, 6, 6, 13})) // 应输出[6 9]

	fmt.Println(solution(9, 40, []int{1, 11, 13, 12, 7, 8, 11, 5, 6})) // 应输出[0 0]
}
